package com.googlecode.cswish.struts.interceptor;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.googlecode.cswish.util.FrameConstant;
import com.opensymphony.xwork2.ValidationAware;

public class FileUploadInterceptor extends org.apache.struts2.interceptor.FileUploadInterceptor {

	protected boolean acceptFile(Object action, File file, String filename, String contentType, String inputName, ValidationAware validation) {
		boolean ret = super.acceptFile(action, file, filename, contentType, inputName, validation);
		
		if (ret) {
			if (action instanceof Map) {
				List<String> fileNames = (List<String>)((Map)action).get(FrameConstant.STACK_UPLOADFILES);
				if (fileNames == null) {
					fileNames = new ArrayList<String>();
					((Map)action).put(FrameConstant.STACK_UPLOADFILES, fileNames);
				}
				fileNames.add(inputName);
			}
		}
		return ret;
	}
}
